package com.example.dblibrary.app.dbManager;

import android.util.Log;

import com.example.dblibrary.app.ActivityBasePresenter;
import com.example.dblibrary.app.BaseActivity;
import com.example.dblibrary.database.daos.SingerIndexConstant;
import com.example.dblibrary.database.entities.Singer;
import com.example.dblibrary.database.entities.Song;

import java.util.ArrayList;
import java.util.List;

import io.reactivex.Flowable;
import io.reactivex.functions.Consumer;
import io.reactivex.schedulers.Schedulers;

public class DbPresenter extends ActivityBasePresenter<DbModel, DbContract.BaseHomeView> implements DbContract.BaseHomePresenter {
    public DbPresenter(BaseActivity context) {
        super(context);
    }

    @Override
    public DbModel bindModel() {
        return new DbModel(this.mAppDatabase);
    }

    @Override
    public void initData() {
        super.initData();
    }

    @Override
    public Flowable<List<Singer>> loadSingerByDim(int start, int offset, int type, String typeContent, int area, String areaContent, int firstSpell, String firstSpellContent, int handleSpell, String handleSpellContent) {
        return mModel.loadSingerByDim(start,offset,type,typeContent,area,areaContent,firstSpell,firstSpellContent,handleSpell,handleSpellContent);
    }

    @Override
    public Flowable<List<Song>> loadSongByDim(int start, int offset, int category, int categoryContent, int firstSpell, String firstSpellContent, int handleSpell, String handleSpellContent, int state) {
        return mModel.loadSongByDim(start,offset,category,categoryContent,firstSpell,firstSpellContent,handleSpell,handleSpellContent,state);
    }


//    @Override
//    public void getSingersByPage(int start, int offset) {
//        mView.laodingData();
//
//        Log.e("getSingersByPage","启动加载数据");
//        mView.showingDailog();
//
//        mModel.loadSingerByOffset(start,offset).subscribeOn(Schedulers.newThread())//使被观察者存在独立的线程执行
//                .observeOn(Schedulers.newThread())//使观察者存在独立的线程执行
//                .subscribe(new Consumer<List<Singer>>() {
//                    @Override
//                    public void accept(List<Singer> singers) throws Exception {
//
//                        mView.loadedData();
//                        Log.e("getSingersByPage","加载数据完成");
//
//                        mView.hidingDailog();
//
//                        Log.e("getSingersByPage","隐藏对话框");
//
//                        mView.refreshSinger(singers);
//                    }
//                });
//    }
}
